import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { Language } from "../../../../extend/language/Language";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { PetHireShowType } from "./PetHireShowType";
import { EPetRentVison } from "../../../../Message/Game/EPetRentVison";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { PetUtil } from "../pet/info/PetUtil";
import { PetType } from "../pet/info/PetType";
import { PetColor } from "../pet/info/PetColor";
import { Cache } from "../../cache/Cache";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { PetItem } from "../pet/PetItem";
import { RadioButtonGroup } from "../../../../fl/controls/RadioButtonGroup";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SPetRent } from "../../../../Message/Game/SPetRent";
import { All } from "../../../../PetHireShowType/All";
import { _EPetRentVisonAll } from "../../../../EPetRentVison/_EPetRentVisonAll";
import { Camp } from "../../../../PetHireShowType/Camp";
import { _EPetRentVisonCamp } from "../../../../EPetRentVison/_EPetRentVisonCamp";
import { Guild } from "../../../../PetHireShowType/Guild";
import { _EPetRentVisonGuild } from "../../../../EPetRentVison/_EPetRentVisonGuild";
import { _priceUnit } from "../../../../this/_priceUnit";
type int = number;
//class PetHireApplyRenderer
    
    export  class PetHireApplyRenderer extends GCellRenderer
    {
        constructor()
        {
            this._conditionArray = [{"name": Language.getString(54194), "value": 40}, {"name": Language.getString(54208), "value": 601}, {"name": Language.getString(54191), "value": 24}, {"name": Language.getString(54192), "value": 10}];
            this._cTxtArray = [];
            this._showDp = new DataProvider([{"label": All, "value": _EPetRentVisonAll}, {"label": Camp, "value": _EPetRentVisonCamp}, {"label": Guild, "value": _EPetRentVisonGuild}]);
            super();
            this.init();
            this.mouseEnabled = false;
            this.mouseChildren = false;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._petInfo = arg1 as SPetInfo;
            if (this._petInfo) 
            {
                this._petItem.dragSource = this._petInfo;
                this._levelTxt.text = Language.getStringByParam(28023, this._petInfo.reinLevel, this._petInfo.level);
                if (this._petInfo.code != this._petInfo.changeCode) 
                {
                    this._changeStr = HTMLUtil.addColor(Language.getString(54238), GlobalStyle.color6);
                }
                this._nameTxt.htmlText = this._changeStr + PetUtil.getPetName(this._petInfo);
                this._typeTxt.htmlText = HTMLUtil.addColor(PetType.getTypeName(this._petInfo.career), PetType.getTypeColor(this._petInfo.career));
                this._talentTxt.htmlText = HTMLUtil.addColor(this._petInfo.talent.toString(), PetColor.getTalentColor(this._petInfo).color);
                this._growthTxt.htmlText = HTMLUtil.addColor(this._petInfo.growth.toString(), PetUtil.getUpgradeColor(true, this._petInfo.growth));
                this._spiritTxt.htmlText = HTMLUtil.addColor(this._petInfo.spirit.toString(), PetUtil.getUpgradeColor(false, this._petInfo.spirit));
                this._applyedRent = Cache.instance.petHire.getApplyedPetRent(this._petInfo.uid);
                loc1 = "";
                if (this._applyedRent) 
                {
                    this._infoSprite.visible = true;
                    this._applySprite.visible = false;
                    this._conditionSprite.visible = false;
                    if (this._applyedRent.rentCount != 5) 
                    {
                        loc1 = loc1 + Language.getString(54334);
                        loc1 = loc1 + (PetHireShowType.getShowTypeName(this._applyedRent.vison) + "\n");
                        loc1 = loc1 + Language.getStringByParam(54335, this._applyedRent.rentCount);
                        this._isChangePrice = true;
                    }
                    else 
                    {
                        loc1 = loc1 + Language.getStringByParam(54333, this._applyedRent.rentCount);
                        this._isChangePrice = false;
                    }
                    this._infoTxt.htmlText = "<textFormat leading=\'5\'>" + loc1 + "</textFormat>";
                }
                else 
                {
                    this._infoSprite.visible = false;
                    if (PetUtil.isPetCanApply(this._petInfo)) 
                    {
                        this._applySprite.visible = true;
                        this._conditionSprite.visible = false;
                    }
                    else 
                    {
                        this._conditionSprite.visible = true;
                        this._applySprite.visible = false;
                        this.updateColor();
                    }
                    this._isChangePrice = false;
                }
                this.dealChangePrice(this._isChangePrice);
            }
            return;
        }

        /* internal  */dealChangePrice(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._applySprite.visible = true;
                this._setPriceTxt.visible = false;
                this._showComboBox.visible = false;
                this._applyBtn.label = Language.getString(54596);
                this._applyBtn.setSize(70, 24);
                this._applyBtn.toolTipData = Language.getString(54599);
                this._priceInput.text = this._applyedRent.sellPrice.toString();
                if (this._applyedRent.sellUnit != EPrictUnit._EPriceUnitCoin) 
                {
                    this._goldRadio.selected = true;
                }
                else 
                {
                    this._coinRadio.selected = true;
                }
                this._coinRadio.drawNow();
                this._goldRadio.drawNow();
            }
            else 
            {
                this._setPriceTxt.visible = true;
                this._showComboBox.visible = true;
                this._applyBtn.label = Language.getString(54338);
                this._applyBtn.setSize(60, 24);
                this._applyBtn.toolTipData = null;
                this._priceInput.text = "";
            }
            this._applyBtn.drawNow();
            return;
        }

        /* internal  */init(): void
        {
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=0;
            this._showDp = this.getShowComboDp();
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            var loc2=40;
            var loc3=45;
            ObjCreate.createBg(0, 0, 590, 90, this);
            ObjCreate.createBg(20, 15, 38, 38, this, ImagesConst.PackItemBg);
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            this._petItem.setSize(32, 32);
            this._petItem.move(22, 17);
            this.addChild(this._petItem);
            ObjCreate.createTextField("LV.", 2, 65, 40, 25, this, loc1);
            this._levelTxt = ObjCreate.createTextField("", 24, 65, 40, 25, this, loc1);
            this._levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt = ObjCreate.createTextField("", 75, 15, 100, 25, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(75, loc2, 75, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54336), 86, loc3, 60, 20, this);
            this._typeTxt = ObjCreate.createTextField("", 75, 65, 75, 20, this, GlobalStyle.textFormat6);
            this._typeTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(155, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54176), 163, loc3, 60, 20, this);
            this._talentTxt = ObjCreate.createTextField("", 155, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._talentTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(205, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54177), 213, loc3, 60, 20, this);
            this._growthTxt = ObjCreate.createTextField("", 205, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._growthTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(255, loc2, 45, 45, this, ImagesConst.AttrBg);
            ObjCreate.createTextField(Language.getString(54178), 264, loc3, 60, 20, this);
            this._spiritTxt = ObjCreate.createTextField("", 255, 65, 45, 20, this, GlobalStyle.textFormat6);
            this._spiritTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._infoSprite = new Object /* flash.display.Sprite */();
            this._infoSprite.x = 320;
            this._infoSprite.y = 15;
            this._infoTxt = ObjCreate.createTextField("", 0, 0, 240, 70, this._infoSprite);
            this._infoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt.visible = true;
            this.addChild(this._infoSprite);
            this._applySprite = new Object /* flash.display.Sprite */();
            this._applySprite.x = 320;
            this._applySprite.y = 15;
            this._setPriceTxt = ObjCreate.createTextField(Language.getString(54337), 0, 0, 100, 40, this._applySprite, GlobalStyle.textFormat2);
            this._unitRadioGroup = new RadioButtonGroup("unit");
            this._unitRadioGroup.addEventListener(flash.events.Event.CHANGE, this.onUintChangeHandler);
            this._priceInput = ObjCreate.createGTextInput(105, 5, 65, 20, this._applySprite);
            this._priceInput.restrict = "0-9";
            this._priceInput.addEventListener(flash.events.Event.CHANGE, this.onPriceChangeHandler);
            this._coinRadio = ObjCreate.createRadioButton("", 175, -5, 20, 20, this._applySprite);
            this._coinRadio.selected = true;
            this._coinRadio.value = EPrictUnit._EPriceUnitCoin;
            this._coinRadio.group = this._unitRadioGroup;
            this._coinRadio.drawNow();
            this._coinRadio.addEventListener(flash.events.Event.CHANGE, this.onUintChangeHandler);
            ObjCreate.createBitmap(ImagesConst.Tongqian_small, 200, -2, this._applySprite);
            ObjCreate.createTextField(Language.getString(54329), 225, -2, 75, 20, this._applySprite);
            this._goldRadio = ObjCreate.createRadioButton("", 175, 15, 20, 20, this._applySprite);
            this._goldRadio.value = EPrictUnit._EPriceUnitGold;
            this._goldRadio.group = this._unitRadioGroup;
            this._goldRadio.drawNow();
            this._goldRadio.addEventListener(flash.events.Event.CHANGE, this.onUintChangeHandler);
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 200, 18, this._applySprite);
            ObjCreate.createTextField(Language.getString(54328), 225, 20, 75, 18, this._applySprite);
            this._showComboBox = ObjCreate.createGComboBox(0, 45, 150, 25, this._showDp, this._applySprite);
            this._showComboBox.drawNow();
            this._applyBtn = ObjCreate.createGButton(Language.getString(54338), 175, 45, 60, 24, this._applySprite);
            this._applyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onApplyBtnClickHandler);
            this._applyBtn.drawNow();
            this.addChild(this._applySprite);
            this._conditionSprite = new Object /* flash.display.Sprite */();
            this._conditionSprite.x = 320;
            this._conditionSprite.y = 15;
            ObjCreate.createTextField(Language.getString(54339), 0, 0, 220, 30, this._conditionSprite, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            ObjCreate.createTextField(Language.getString(54340), 0, 30, 220, 20, this._conditionSprite, new GTextFormat(FontUtil.songtiName, 12, 16742658));
            var loc8=0;
            while (loc8 < this._conditionArray.length) 
            {
                loc6 = (loc4 = this._conditionArray[loc8]).name as string;
                loc7 = loc4.value as int;
                (loc5 = ObjCreate.createTextField(loc6 + "：" + loc7, 90, 0, 220, 20, this._conditionSprite, GlobalStyle.textFormat5)).x = 60 + loc8 % 2 * 60;
                loc5.y = 30 + Math.floor(loc8 / 2) * 25;
                this._cTxtArray.push(loc5);
                ++loc8;
            }
            this.addChild(this._conditionSprite);
            return;
        }

        /* internal  */updateColor(): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._cTxtArray.length) 
            {
                loc1 = this._cTxtArray[loc2] as Object /* flash.text.TextField */;
                loc1.textColor = this.getConditionColor(loc2);
                ++loc2;
            }
            return;
        }

        /* internal  */getConditionColor(arg1: int): uint
        {
            var loc1=0;
            if (arg1 != 0) 
            {
                if (arg1 != 1) 
                {
                    if (arg1 != 2) 
                    {
                        if (arg1 == 3) 
                        {
                            loc1 = this._petInfo.spirit >= 10 ? 65280 : 16711680;
                        }
                    }
                    else 
                    {
                        loc1 = this._petInfo.growth >= 24 ? 65280 : 16711680;
                    }
                }
                else 
                {
                    loc1 = this._petInfo.talent >= 601 ? 65280 : 16711680;
                }
            }
            else 
            {
                loc1 = PetUtil.getFourDigitLevel(this._petInfo.reinLevel, this._petInfo.level) >= 40 ? 65280 : 16711680;
            }
            return loc1;
        }

        /* internal  */onUintChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            this._priceUnit = int(this._unitRadioGroup.selectedData);
            if (this._priceUnit != EPrictUnit._EPriceUnitCoin) 
            {
                loc1 = Language.getString(54342);
            }
            else 
            {
                loc1 = Language.getString(54341);
            }
            this._priceInput.toolTipData = HTMLUtil.addColor(loc1, "#ffffff");
            arg1.stopPropagation();
            return;
        }

        /* internal  */onPriceChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            arg1.stopPropagation();
            return;
        }

        /* internal  */onApplyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=0;
            if (this._petInfo) 
            {
                loc1 = int(this._priceInput.text);
                if (this._priceInput.text == "" || loc1 == 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54348));
                    return;
                }
                if (this._priceUnit != EPrictUnit._EPriceUnitCoin) 
                {
                    if (loc1 < 2) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54350));
                        return;
                    }
                }
                else if (loc1 < 2000) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(54349));
                    return;
                }
                if (this._isChangePrice) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireChangeRentPrice, {"uid": this._petInfo.uid, "price": loc1, "unit": _priceUnit}));
                }
                else 
                {
                    if (int(this._petInfo.energy / 3 <= 0)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54343));
                        return;
                    }
                    if (PetUtil.getFourDigitLevel(this._petInfo.reinLevel, this._petInfo.level) < 40) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54344));
                        return;
                    }
                    if (this._petInfo.talent < 601) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54345));
                        return;
                    }
                    if (this._petInfo.growth < 24) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54346));
                        return;
                    }
                    if (this._petInfo.spirit < 10) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(54347));
                        return;
                    }
                    loc2 = int(this._showComboBox.selectedItem.value);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireApply, {"uid": this._petInfo.uid, "price": loc1, "priceUnit": _priceUnit, "vision": loc2}));
                }
            }
            return;
        }

        public getShowComboDp(): DataProvider
        {
            var loc1=null;
            if (Cache.instance.guild.myGuildInfo) 
            {
                loc1 = new DataProvider([{"label": All, "value": _EPetRentVisonAll}, {"label": Camp, "value": _EPetRentVisonCamp}, {"label": Guild, "value": _EPetRentVisonGuild}]);
            }
            else 
            {
                loc1 = new DataProvider([{"label": All, "value": _EPetRentVisonAll}, {"label": Camp, "value": _EPetRentVisonCamp}]);
            }
            return loc1;
        }

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_typeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_talentTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_growthTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_spiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_infoSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_infoTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_applySprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_setPriceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceInput: GTextInput;

        /* internal */ /* var */_unitRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_coinRadio: GRadioButton;

        /* internal */ /* var */_goldRadio: GRadioButton;

        /* internal */ /* var */_showComboBox: GComboBox;

        /* internal */ /* var */_applyBtn: GButton;

        /* internal */ /* var */_conditionArray: Array<any>;

        /* internal */ /* var */_cTxtArray: Array<any>;

        /* internal */ /* var */_showDp: DataProvider;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_applyedRent: SPetRent;

        /* internal */ /* var */_changeStr: string="";

        /* internal */ /* var */_isChangePrice: Boolean;

        /* internal */ /* var */_priceUnit: int;

        /* internal */ /* var */_conditionSprite: Object /* flash.display.Sprite */;
    }
